/**
 * \file       :	MS5611.h
 * \brief      :	This file provides code for the configuration of the Barometric Pressure Sensor MS5611.
 * \author     :	Huangj
 * \version    :	V1.0
 */
#ifndef __MS5611_H
#define __MS5611_H
#include "stm32f4xx_hal.h"
#include <stdlib.h>
#include "main.h"
//#include "nrutil.h"
#define MS5611_TIMEOUT_MAX			1000
#define MS5611_ADDRESS_WRITE		0xEE
#define MS5611_ADDRESS_READ 		0xEF
#define MS5611_D1								0x40
#define MS5611_D2								0x50
#define MS5611_RESET						0x1E
/********************************************
 * Pressure accuracy
 ********************************************/
#define MS5611_D1_OSR_256				0x40		
#define MS5611_D1_OSR_512				0x42
#define MS5611_D1_OSR_1024			0x44
#define MS5611_D1_OSR_2048			0x46
#define MS5611_D1_OSR_4096			0x48
/********************************************
 * Temperature accuracy
 ********************************************/
#define MS5611_D2_OSR_256				0x50		
#define MS5611_D2_OSR_512				0x52
#define MS5611_D2_OSR_1024			0x54
#define MS5611_D2_OSR_2048			0x56
#define MS5611_D2_OSR_4096			0x58
#define MS5611_ADC_READ					0x00
#define MS5611_PROM_READ				0xA0
#define MS5611_PROM_CRC					0xAE

typedef struct _ms5611_dat
{
    int32_t  _height; 
    uint32_t _pressure;    
    
}ms5611_dat_t;

extern float atmospheric_pressure_value[];
extern float metre[];

extern ms5611_dat_t *gp_ms5611_dat;



void ms5611_reset(void);
uint8_t ms5611_read_prom(void);
uint32_t ms5611_do_conversion(uint16_t accuracy);
void ms5611_calculate_temperature(void);
void ms5611_calculate_pressure(void);
void ms5611_init(void);
void ms5611_get_data(int32_t *height, uint32_t *pressure);

/* the following four functions calculate the height */
void spline(float x[], float y[], int n, float yp1, float ypn, float y2[]);
void free_vector(float *v, long nl, long nh);
float *vector(long nl, long nh);
void splint(float xa[], float ya[], float y2a[], int n, float x, float *y);


#endif /*__MS5611_H*/
